package com.etymgiko.spaceshipshop.web;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import javax.servlet.http.HttpServletRequest;

/**
 * Login form.
 *
 * @author Ivan Holub
 */
public class LoginForm extends ActionForm {

    /**
     * Login.
     */
    private String username;

    /**
     * Password.
     */
    private String password;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
        ActionErrors errors = new ActionErrors();

        // Name must be entered
        if ((username == null) || (username.length() < 1)) {
            errors.add("name", new ActionMessage("errors.name.required"));
        }

        // Password must be entered
        if ((password == null) || (password.length() < 1)) {
            errors.add("secret", new ActionMessage("errors.password.required"));
        }

        return errors;
    }
}
